<template>
  <div>
    <el-form :model="form" :rules="rules" ref="formRef">
      <el-form-item label="获取途径1:" prop="shareRecord" :label-width="formLabelWidth">
        <span class="title">分享获取积分数量:</span>
        <el-input-number
          type="number"
          :min="0"
          controls-position="right"
          v-model="form.shareRecord"
          :precision="0"
          :step="1"
          style="margin-left:15px"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="获取途径2:" prop="picRecord" :label-width="formLabelWidth">
        <span class="title">评论上传图片获取积分数量:</span>
        <el-input-number
          type="number"
          :min="0"
          controls-position="right"
          v-model="form.picRecord"
          :precision="0"
          :step="1"
          style="margin-left:15px"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="获取途径3:" required :label-width="formLabelWidth">
        <span class="title">评论到达:</span>
        <el-input-number
          type="number"
          :min="0"
          controls-position="right"
          v-model="form.commentNum"
          :precision="0"
          :step="1"
          style="margin-left:15px"
        ></el-input-number>
        <span class="title">字获取</span>
        <el-input-number
          type="number"
          :min="0"
          controls-position="right"
          v-model="form.commenytRecord"
          :precision="0"
          :step="1"
          style="margin-left:15px"
        ></el-input-number>
        <span class="title">积分</span>
      </el-form-item>
      <el-form-item label="获取途径4:" prop="defaultNum" :label-width="formLabelWidth">
        <span class="title">评论没有达到字数获取:</span>
        <el-input-number
          type="number"
          :min="0"
          controls-position="right"
          v-model="form.defaultNum"
          :precision="0"
          :step="1"
          style="margin-left:15px"
        ></el-input-number>
        <span class="title">积分</span>
      </el-form-item>
    </el-form>
    <div style="text-align:center; margin-top: 50px;">
      <el-button type="primary" @click="submitForm('formRef')" v-if="isPermissionsBtn('integralSet_add')">保存</el-button>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
  name: "",
  data() {
    return {
      IntegralId: "",
      formLabelWidth: "100px",
      form: {
        shareRecord: "",
        picRecord: "",
        defaultNum: "",
        commentNum: "",
        commenytRecord: ""
      },
      rules: {
        shareRecord: [
          { required: true, message: "请输入数量", trigger: "blur" }
        ],
        picRecord: [{ required: true, message: "请输入数量", trigger: "blur" }],
        defaultNum: [
          { required: true, message: "请输入积分", trigger: "blur" }
        ],
        commentNum: [
          { required: true, message: "请输入数量", trigger: "blur" }
        ],
        commenytRecord: [
          { required: true, message: "请输入积分", trigger: "blur" }
        ]
      }
    };
  },
  components: {},
  computed: {
     ...mapGetters(["isPermissionsBtn"])
  },
  beforeMount() {},
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.$service.recordrulesSelectAll().then(res => {
        if (res.code == "00000") {
          this.form.shareRecord = res.data.shareRecord;
          this.form.picRecord = res.data.picRecord;
          this.form.commentNum = res.data.commentNum;
          this.form.commenytRecord = res.data.commenytRecord;
          this.form.defaultNum = res.data.defaultNum;
          this.IntegralId = res.data.id;
        }
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        let message = this.form;
        if (valid) {
          let param = {
            id: this.IntegralId,
            shareRecord: message.shareRecord,
            picRecord: message.picRecord,
            commentNum: message.commentNum,
            commenytRecord: message.commenytRecord,
            defaultNum: message.defaultNum
          };

          this.$service.recordrulesUpdate(param).then(res => {
            if (res.code == "00000") {
              this.$message({
                message: "成功",
                type: "success"
              });
            } else {
              this.$message({
                message: res.message,
                type: "warning"
              });
            }
          });
        }
      });
    }
  },
  watch: {}
};
</script>
<style scoped>
</style>
